﻿
Partial Class Pages_School
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Kollar om querystringen innehåller ett ID isåfall Lista upp vald nyhet
        If Request.QueryString("id") IsNot Nothing Then
            Dim news = New NewsDAO().getOneNews(Request.QueryString("id"))

            pnlNews.Visible = True
            lblHeader.Text = news.Header
            lblText.Text = news.Texten
            lblDate.Text = news.DateNews
        Else
            'Listar upp nyheterna
            rptNews.DataSource = New NewsDAO().GetAllNewsSchoolWork()
            rptNews.DataBind()
            pnlNews.Visible = False
        End If
    End Sub

    'Sätter ID på varje artikel
    Protected Sub rptNews_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptNews.ItemDataBound
        Dim link As HyperLink
        link = CType(e.Item.FindControl("hplReadMore"), HyperLink)

        Dim NewsDao = New NewsDAO().GetAllNewsSchoolWork
        Dim News As News
        News = CType(e.Item.DataItem, News)
        Dim id = News.NewsID

        link.NavigateUrl = "School.aspx?id=" & id

    End Sub
End Class
